package com.zhuangjie.security.config;

import com.zhuangjie.security.intercepor.UserRequestInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 *
 * @author zhuangjie
 * @date 2023/10/03
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private UserRequestInterceptor userRequestInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(userRequestInterceptor);
        registration.addPathPatterns("/**"); //所有路径都被拦截
        registration.excludePathPatterns(    //添加不拦截路径
                "/**/login",                    //登录路径
                "/error",
                "/**/*.html",                //html静态资源
                "/**/*.js",                  //js静态资源
                "/**/*.css",                  //css静态资源
                "exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*," // Druid面板
        );
        // 开放knife4j的相关内容
        registration.excludePathPatterns(
                "/v2/api-docs",
                "/configuration/ui",
                "/swagger-resources/**",
                "/configuration/security",
                "/swagger-ui.html",
                "/webjars/**"
        );
    }
}